home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / UTILITY / DUPV1.ARJ / DUP.C < prev    next >
Text File  |  1991-05-23  |  2KB  |  69 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. #define CR "\r\n"
  5.  
  6. char tank1[80]={""};
  7. char tank2[80]={""};
  8. char command[80];
  9.  
  10. void instructions(int clrflg){
  11. char *str="" CR CR
  12. "PURPOSE:  DUPlicate a command on the files/directories listed in FILE.LST." CR
  13. "          This will allow you to execute one command on numerous (specific)" CR
  14. "          files or directories." CR CR
  15. "  USAGE:  DUP COMMAND * [arguments]" CR CR
  16. "          The asterisk will be replaced with names in FILE.LST.  If an " CR
  17. "          asterisk is not present the filenames will be placed at the end" CR
  18. "          of the command line." CR CR
  19. "EXAMPLE:  DUP DEL              ;Delete all files in FILE.LST" CR
  20. "          DUP MD               ;Make directories from FILE.LST" CR
  21. "          DUP RD               ;Remove directories contained in FILE.LST" CR CR
  22. "NOTE: Pipes and redirection must be surrounded by quotes.  EXAMPLE:"CR
  23. "          DUP echo y \"|\" del   ; remove all files from directories specified" CR
  24. "                               ; in FILE.LST"CR
  25. "          DUP dir * \">>\" DRS   ; ASCII text file DRS created with listing of " CR
  26. "                               ; directory names (from FILE.LST)" CR;
  27.  
  28.     if(clrflg==0)
  29.         clrscr();
  30.     cprintf("%s",str);
  31.     exit(1);
  32. }
  33.  
  34. char *make_command(char *str){
  35.     char *ptr;
  36.     strcpy(command,tank1);
  37.     strcat(command,str);
  38.     strcat(command,tank2);
  39.     if((ptr=strstr(command,"\n"))!=NULL)
  40.         *ptr=' ';
  41.     printf("\n%s\n",command);
  42.     system(command);
  43. }
  44.  
  45. main(int argc, char *argv[]){
  46.     int i;
  47.     char buffer[256];
  48.     char *ptr;
  49.     FILE *in;
  50.     ptr=tank1;
  51.     if(argc<2) instructions(0);
  52.     for(i=1;i<argc;i++){
  53.         if((strcmp(argv[i],"*"))==0)
  54.             ptr=tank2;
  55.         else {
  56.             strcat(ptr,argv[i]);
  57.             strcat(ptr," ");
  58.         }
  59.     }
  60.     if((in=fopen("file.lst","rt"))==NULL){
  61.         clrscr();
  62.         printf("\nCannot find the file FILE.LST to duplicate the command \"%s * %s\"",tank1,tank2);
  63.         instructions(1);
  64.     }
  65.     while((fgets(buffer,256,in))!=NULL)
  66.         make_command(buffer);
  67.     fclose(in);
  68.     exit(0);
  69. }